﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Data.Business;
using NLBS.Framework;

namespace NLBS.Validate
{
   public class CommentValidate:ValidateTemplete<Comment>
    {

       
        public override void checkPower()
        {
            switch (Act)
            {
                case Action.Update:
                    if (power.Edit < 1)
                        throw new Exception("没有权限进行此操作");
                    break;
                case Action.Delete:
                    if (power.Delete < 1)
                        throw new Exception("没有权限进行此操作");
                    break;
            }
          
        }

        public CommentValidate(Action act,int keyID)
        {
            this.Act = act;
            this.keyID = keyID;
        }

        public override void checkArgument()
        {
            
           // throw new NotImplementedException();
        }


        public override void checkEntity()
        {
            //this.Entity = CommentData.GetCommentByID(this.keyID);
            if (this.Entity == null)
            {
                throw new Exception("评论不存在");
            }
        }

        public override void checkPowerAgain()
        {
            User currentUser = BlogInfo.Instance().CurrentUser;
            switch (Act)
            {
                case Action.Update:
                    if (power.Edit < 1)
                        throw new Exception("没有权限进行此操作");
                    break;
                case Action.Delete:
                    if (currentUser.UserID != this.Entity.Article.AuthorID && currentUser.UserID != this.Entity.AuthorID && power.Delete < 2)
                    {
                        throw new Exception("没有权限进行此操作");
                    }
                    break;
            }
            
        }
    }
}
